//
// Created by Chen qin lang on 2018/7/6.
//

#ifndef CQAUDIO_WLFFMPEG_H
#define CQAUDIO_WLFFMPEG_H

#include "pthread.h"
#include "JavaCall.h"
#include <android/log.h>
#include "WlAudio.h"
extern "C"{
#include "libavformat/avformat.h"
#include "libavcodec/avcodec.h"
#include <libavutil/time.h>
};
#ifdef WIN32
#define INT64_MIN    0x8000000000000000i64
 #define INT64_MAX    0x7FFFFFFFFFFFFFFFi64
#else
#define INT64_MIN    0x8000000000000000LL
#define INT64_MAX    0x7FFFFFFFFFFFFFFFLL
#endif

#define LOGE(format, ...) __android_log_print(ANDROID_LOG_ERROR,"(><)",format, ##__VA_ARGS__);
class WlFFmpeg {
public:
    JavaCall* call=NULL;
    const char* url;
    pthread_t pthread_play;
    AVFormatContext *pFormatContext=NULL;
    WlAudio *audio=NULL;
    WlPlayStat *playStats=NULL;
    pthread_mutex_t decode_mutex;//对解码过程上锁,防止多次加载错误
    bool isexit= false;
    int duration;
    int volumeProcess;

    pthread_mutex_t seek_mutex;//时间点锁
public:
    WlFFmpeg(WlPlayStat *playStat,JavaCall *call, const char *url);
    ~WlFFmpeg();
    void prepared();
    void decodeThread();
    void start();
    void resume();
    void pause();
    void release();
    void seek(int seconds);
    void setVolume(int process);
    void setMuter(int channels);
    void setPitch(float pitch);
    void setTempo(float pitch);
};


#endif //CQAUDIO_WLFFMPEG_H
